package com.share.exam;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @desc:
 * @author:caifan
 * @date:2020/5/24
 */
public class Main {

    public static ArrayList<Integer> GetLeastNumbers_Solution(int[] input, int k) {
//        Arrays.sort(input);jdk子带排序方法
        bubbleSort(input);
        ArrayList<Integer> arrayList = new ArrayList();
        if (k > input.length) {
            throw new RuntimeException("超出长度");
        }
        for (int i=0;i<k;i++) {
            arrayList.add(input[i]);
        }
        return arrayList;

    }

    /**
     * 排序
     * @param input
     * @return
     */
    private static void bubbleSort(int[] input) {
        int len = input.length;
        for (int i=0;i<len;i++) {
            for (int j=i+1; j < len; j++) {
                if (input[i] > input[j]) {
                    int temp = input[i];
                    input[i] = input[j];
                    input[j] = temp;
                }
            }
        }
    }


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        while (in.hasNextLine()) {
            String line = in.nextLine();
            int k = Integer.parseInt(in.nextLine());
            int[] input = spliteLine(line);
            ArrayList<Integer> res = GetLeastNumbers_Solution(input, k);
            System.out.println(res);
        }
    }

    private static int[] spliteLine(String line) {
        String[] split = line.split(", *+");//将输入行的数据解析成字符数组
        int[] scannerNumber = new int[split.length];
        if (split.length > 0) {
            for (int i = 0; i < split.length; i++) {
                scannerNumber[i] = Integer.parseInt(split[i]);
            }
        }
        return scannerNumber;
    }
}
